﻿var openw;
var w;//popup Openid

$(document).ready(function() {
    openw = function(au, url) {
        openPopupWindow(au, url);
    };
});

function getCenteredCoords(width, height) {
    var xPos = null;
    var yPos = null;
    if (window.ActiveXObject) {
        xPos = window.event.screenX - (width / 2) + 100;
        yPos = window.event.screenY - (height / 2) - 100;
    } else {
        var parentSize = [window.outerWidth, window.outerHeight];
        var parentPos = [window.screenX, window.screenY];
        xPos = parentPos[0] + Math.max(0, Math.floor((parentSize[0] - width) / 2));
        yPos = parentPos[1] + Math.max(0, Math.floor((parentSize[1] - (height * 1.25)) / 2));
    }
    return [xPos, yPos];
}

function openPopupWindow(au, url) {
    w = window.open("/loginau?au=" + encodeURIComponent(au) + "&url=" + url, "LoginAuthenticationPopup", "width=450, height=500, location=1, status=1, resizable=yes");
    var coords = getCenteredCoords(450, 500);
    w.moveTo(coords[0], coords[1]);
}

function valueCallBackRegister(value) {
    w.close();
    window.location = "/register?u=" + value;
}

function valueCallBackLogin(url) {
    w.close();
    window.location = url;
}

function ErrorCallBackLogin(result) {
    w.close();
    jAlert(result);
}